using System;

namespace Nvigorate.WCF
{
    public abstract class BaseServiceProxy<TContract> where TContract : class
    {
        protected virtual void Execute(Action<TContract> action)
        {
            using (var proxy = Proxy)
            {
                proxy.Call(action);
            }
        }

        protected virtual TResult Execute<TResult>(Func<TContract, TResult> action)
        {
            using (var proxy = Proxy)
            {
                return proxy.Call(action);
            }
        }

        protected ServiceClient<TContract> Proxy
        {
            get { return ServiceClientFactory.GetClient<TContract>(); }
        }
    }
}